package com.ruoyi.xp.custom.service.impl;

import java.util.Date;
import java.util.List;

import cn.hutool.core.date.DateTime;
import com.ruoyi.common.utils.security.PermissionUtils;
import com.ruoyi.xp.custom.constant.CustomConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.xp.custom.mapper.CustomServiceTraceMapper;
import com.ruoyi.xp.custom.domain.CustomServiceTrace;
import com.ruoyi.xp.custom.service.ICustomServiceTraceService;
import com.ruoyi.common.core.text.Convert;

/**
 * 客服问题追踪记录Service业务层处理
 * 
 * @author chdx
 * @date 2022-11-30
 */
@Service
public class CustomServiceTraceServiceImpl implements ICustomServiceTraceService 
{
    @Autowired
    private CustomServiceTraceMapper customServiceTraceMapper;

    /**
     * 查询客服问题追踪记录
     * 
     * @param customServiceTraceId 客服问题追踪记录主键
     * @return 客服问题追踪记录
     */
    @Override
    public CustomServiceTrace selectCustomServiceTraceByCustomServiceTraceId(Long customServiceTraceId)
    {
        return customServiceTraceMapper.selectCustomServiceTraceByCustomServiceTraceId(customServiceTraceId);
    }

    /**
     * 查询客服问题追踪记录列表
     * 
     * @param customServiceTrace 客服问题追踪记录
     * @return 客服问题追踪记录
     */
    @Override
    public List<CustomServiceTrace> selectCustomServiceTraceList(CustomServiceTrace customServiceTrace)
    {
        return customServiceTraceMapper.selectCustomServiceTraceList(customServiceTrace);
    }

    /**
     * 新增客服问题追踪记录
     * 
     * @param customServiceTrace 客服问题追踪记录
     * @return 结果
     */
    @Override
    public int insertCustomServiceTrace(CustomServiceTrace customServiceTrace)
    {
        Long userId = (Long) PermissionUtils.getPrincipalProperty("userId");
        customServiceTrace.setCreateBy(String.valueOf(userId));
        customServiceTrace.setCreateDate(DateTime.now());
        customServiceTrace.setLastUpdateBy(new Long(userId));
        customServiceTrace.setLastUpdateDate(DateTime.now());
        return customServiceTraceMapper.insertCustomServiceTrace(customServiceTrace);
    }

    /**
     * 修改客服问题追踪记录
     * 
     * @param customServiceTrace 客服问题追踪记录
     * @return 结果
     */
    @Override
    public int updateCustomServiceTrace(CustomServiceTrace customServiceTrace)
    {
        Long userId = (Long) PermissionUtils.getPrincipalProperty("userId");
        customServiceTrace.setLastUpdateBy(new Long(userId));
        customServiceTrace.setLastUpdateDate(DateTime.now());
        if (CustomConstants.TRACE_STATUS_CLOSE.equals(customServiceTrace.getTraceStatus())) {
            customServiceTrace.setCloseDate(DateTime.now());
        }
        return customServiceTraceMapper.updateCustomServiceTrace(customServiceTrace);
    }

    /**
     * 批量删除客服问题追踪记录
     * 
     * @param customServiceTraceIds 需要删除的客服问题追踪记录主键
     * @return 结果
     */
    @Override
    public int deleteCustomServiceTraceByCustomServiceTraceIds(String customServiceTraceIds)
    {
        return customServiceTraceMapper.deleteCustomServiceTraceByCustomServiceTraceIds(Convert.toStrArray(customServiceTraceIds));
    }

    /**
     * 删除客服问题追踪记录信息
     * 
     * @param customServiceTraceId 客服问题追踪记录主键
     * @return 结果
     */
    @Override
    public int deleteCustomServiceTraceByCustomServiceTraceId(Long customServiceTraceId)
    {
        return customServiceTraceMapper.deleteCustomServiceTraceByCustomServiceTraceId(customServiceTraceId);
    }
}
